package cn.mall.user.service.impl;

import cn.mall.base.mapper.BaseMapper;
import cn.mall.base.query.BaseQuery;
import cn.mall.base.utils.PageList;
import cn.mall.user.domain.Car;
import cn.mall.user.dto.CarDto;
import cn.mall.user.mapper.CarMapper;
import cn.mall.user.query.CarQuery;
import cn.mall.user.service.ICarService;
import cn.mall.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xizhou
 * @since 2025-01-05
 */
@Service
public class CarServiceImpl extends BaseServiceImpl<Car> implements ICarService {

    @Autowired
    private CarMapper carMapper;


    @Override
    @Transactional
    public void patchRemove(CarDto carDto) {
        carMapper.patchRemoveByCar(carDto);
    }

    @Override
    public PageList<Car> pageList(CarQuery query)  {
        //查询总条数
//        System.out.println(query.getCreateTime());
        long total = carMapper.loadTotal(query);
        if (total > 0){
            List<Car> rows = carMapper.pageList(query);
            return new PageList<Car>(total, rows);
        }
        return new PageList<>();
    }
}
